package cn.jbolt.ec.order_return;

import cn.jbolt.base.JBoltBaseController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;

/**
 * @author xieguo
 */
public class EcOrderReturnController extends JBoltBaseController {
    @Inject
    private OrderReturnService orderReturnService;

    public void order_return(int order_id,String commodities,String reason,String delivery_no){
        JSONObject jo=new JSONObject();
        int[][] id= JSON.parseObject(commodities,int[][].class);
        if (order_id>0&&null!=reason&&null!=commodities&&id[0][0]>0&&id[1][0]>0&&null!=delivery_no){
            if (orderReturnService.order_return(order_id,id,reason,delivery_no)){
                jo.put("ok",0);
                jo.put("msg","申请成功");
                renderJson(jo);
            }else {
                jo.put("ok",1005);
                jo.put("msg","申请超出数量或申请数量不能为零");
                renderJson(jo);
            }
        }else {
            jo.put("ok",1006);
            jo.put("msg","参数异常");
            renderJson(jo);
        }

    }

    public void check_by_status(int member_id,int status){
        JSONObject jo=new JSONObject();
        if (member_id>0&&status>0){
            renderJson(orderReturnService.check_by_status(member_id, status));
        }else {
            jo.put("ok",1006);
            jo.put("msg","参数异常");
            renderJson(jo);
        }

    }

    public void get_info_by_id(int id){
        JSONObject jo=new JSONObject();
        if (id>0){
            renderJson(orderReturnService.get_info_by_id(id));
        }else {
            jo.put("ok",1006);
            jo.put("msg","参数异常");
            renderJson(jo);
        }
    }
}
